package com.regent.central.bill.service.bean;

import com.regent.central.bill.core.DeliveryGoods;
import com.regent.central.bill.repository.DeliveryGoodsMapper;
import com.regent.central.bill.service.DeliveryGoodsService;
import com.regent.central.infrastructure.service.bean.DomainServiceBean;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.Date;
import java.util.List;

@Service
public class DeliveryGoodsServiceBean extends DomainServiceBean<DeliveryGoodsMapper, DeliveryGoods> implements DeliveryGoodsService {

    /**
     * 是否发过此货品
     *
     * @param unitId
     * @param styleId
     * @return true:发过此货品，false：没有发过此货品
     * @throws Exception
     */
    @Override
    public boolean isDeliveryGoods(String unitId, String styleId) throws Exception {
        DeliveryGoods deliveryGoods = mapper.selectDeliveryGoods(unitId, styleId);
        if (StringUtils.isEmpty(deliveryGoods.getId())) {
            return false;
        }
        return true;
    }

    /**
     * 撤销发货货品记录
     *
     * @param userCanceled     撤销人
     * @param deliveryGoodsIds 发货货品记录ID
     */
    @Override
    public void cancel(String userCanceled, String... deliveryGoodsIds) {
        if (deliveryGoodsIds.length == 0) return;
        mapper.cancel(userCanceled, new Date(), deliveryGoodsIds);
    }

    /**
     * 获取销售单的发货货品列表
     *
     * @param saleOrderId 销售单ID
     * @return 销售单的发货货品列表
     */
    @Override
    public List<DeliveryGoods> getSaleOrderDeliveryGoods(String saleOrderId) {
        return getSaleOrderDeliveryGoods(saleOrderId, false, false);
    }

    /**
     * 获取销售单的发货货品列表
     *
     * @param saleOrderId 销售单ID
     * @param canceled    已撤销
     * @param deleted     已删除
     * @return 销售单的发货货品列表
     */
    @Override
    public List<DeliveryGoods> getSaleOrderDeliveryGoods(String saleOrderId, Boolean canceled, Boolean deleted) {
        return mapper.getSaleOrderDeliveryGoods(saleOrderId, canceled, deleted);
    }
}